package cn.com.xjnt.vas.ordering.domain.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import cn.com.xjnt.vas.manage.domain.entity.Organization;

/**
 * The persistent class for the ordering_department database table.
 * 
 */
@Entity
@Table(name = "ordering_department")
@NamedQuery(name = "Department.findAll", query = "SELECT d FROM Department d")
public class Department extends com.frameworks.core.entity.IdEntity {
    private static final long serialVersionUID = 1L;

    private String code;

    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;

    private String name;

    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;
    
    private String cardNo;
    private String remark;
    @ManyToOne
    @JoinColumn(name="organization_id")
    private Organization organization;
    
    // bi-directional many-to-one association to Hospital
    @ManyToOne
    @JoinColumn(name = "hospital_id")
    private Hospital hospital;

    // bi-directional many-to-one association to EmployeeInfo
    @OneToMany(mappedBy = "department")
    private List<EmployeeInfo> employeeInfos;

    public Department() {
    }

    public String getCode() {
        return this.code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Date getCreateTime() {
        return this.createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getUpdateTime() {
        return this.updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Hospital getHospital() {
        return hospital;
    }

    public void setHospital(Hospital hospital) {
        this.hospital = hospital;
    }

    public List<EmployeeInfo> getEmployeeInfos() {
        return this.employeeInfos;
    }

    public void setEmployeeInfos(List<EmployeeInfo> employeeInfos) {
        this.employeeInfos = employeeInfos;
    }

    public EmployeeInfo addEmployeeInfo(EmployeeInfo employeeInfo) {
        getEmployeeInfos().add(employeeInfo);
        employeeInfo.setDepartment(this);

        return employeeInfo;
    }

    public EmployeeInfo removeEmployeeInfo(EmployeeInfo employeeInfo) {
        getEmployeeInfos().remove(employeeInfo);
        employeeInfo.setDepartment(null);

        return employeeInfo;
    }

    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    public String getCardNo() {
        return cardNo;
    }

    public void setCardNo(String cardNo) {
        this.cardNo = cardNo;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    @PrePersist
    public void onCreate() {
        this.createTime = this.updateTime = new Date();
    }

    @PreUpdate
    public void onUpdate() {
        this.updateTime = new Date();
    }
}